package com.potenza.training.interview.controller;

import com.potenza.training.interview.entity.InterviewReplyEntity;
import com.potenza.training.interview.feign.SysServiceFegin;
import com.potenza.training.interview.service.InterviewReplyService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 复盘内容
 *
 * @author lihonggang
 * @email lihonggang@gmail.com
 * @date 2021-07-28 18:57:10
 */
@RestController
@RequestMapping("interview/interviewreply")
public class InterviewReplyController {
    @Autowired
    private InterviewReplyService interviewReplyService;
    @Autowired
    SysServiceFegin sysServiceFegin;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("interview:interviewreply:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = interviewReplyService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("interview:interviewreply:info")
    public R info(@PathVariable("id") Long id){
		InterviewReplyEntity interviewReply = interviewReplyService.getById(id);

        return R.ok().put("interviewReply", interviewReply);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("interview:interviewreply:save")
    public R save(@RequestBody InterviewReplyEntity interviewReply){
        R info = sysServiceFegin.info();
        Map user = (Map) info.get("user");
        interviewReply.setTeacherId(Integer.parseInt(user.get("userId").toString()));
		interviewReplyService.save(interviewReply);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("interview:interviewreply:update")
    public R update(@RequestBody InterviewReplyEntity interviewReply){
		interviewReplyService.updateById(interviewReply);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("interview:interviewreply:delete")
    public R delete(@RequestBody Long[] ids){
		interviewReplyService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 学生查看复盘
     */
    @RequestMapping("/findByUid/{id}/{uid}")
    @RequiresPermissions("interview:interviewreply:findByUid")
    public R findByUid(@PathVariable Integer id,@PathVariable Integer uid){
        InterviewReplyEntity reply = interviewReplyService.findByUid(id,uid);

        return R.ok().put("reply",reply);
    }

    @GetMapping("findReplybyInvitationId/{invitationId}")
    public InterviewReplyEntity findReplybyInvitationId(@PathVariable Integer invitationId){
        return interviewReplyService.findReplybyInvitationId(invitationId);
    }
}
